package com.matuw.android.util;

import java.io.File;
import java.io.IOException;

public class FileUtils {
    /**
     * Create a file if it doesn't exist, otherwise do nothing.
     */
    public static boolean createOrExistsFile(File file) {
        if (file == null) return false;
        if (file.exists()) return file.isFile();
        if (!createOrExistsDir(file.getParentFile())) return false;
        try {
            return file.createNewFile();
        } catch (IOException e) {
            return false;
        }
    }

    /**
     * Create a directory if it doesn't exist, otherwise do nothing.
     */
    public static boolean createOrExistsDir(File file) {
        return file != null && (file.exists() ? file.isDirectory() : file.mkdirs());
    }
}
